<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Vue demo11(列表渲染)</title>
    <script src="../build/vue.js"></script>
</head>
<body>
<div id="app">
    <div>
        <h2>基本用法</h2>
        <ul>
            <li v-for="item in items">
                {{$index}}-{{item.name}}
            </li>
        </ul>
    </div>
    <div>
        <h2>接收参数</h2>
        <ul>
            <li v-for="(index, item) in items">
                {{index}}-{{item.name}}
            </li>
        </ul>
    </div>
    <div>
        <h2>of语法</h2>
        <ul>
            <li v-for="item of items">
                {{$index}}-{{item.name}}
            </li>
        </ul>
    </div>
    <div>
        <h2>对象遍历</h2>
        <ul>
            <li v-for="city in cities">
                {{$key}}-{{city}}
            </li>
        </ul>
    </div>
    <div>
        <h2>列表渲染计算属性</h2>
        <ul>
            <li v-for="num in nums">
                {{num}}
            </li>
        </ul>
    </div>
</div>
<script>
    var vm = new Vue({
        el: '#app',
        data: {
            items: [
                {name: 'xiaobao'},
                {name: 'xiaobaowei'},
                {name: 'weixiaobao'}
            ],
            cities: {
                beijing: 'north',
                shanghai: 'east',
                lanzhou: 'west',
                guilin: 'south'
            }
        },
        computed: {
            nums: function () {
                var nums = [1, 2, 3, 4, 5];
                return nums.map(function (num) {
                    return num + 1;
                });
            }
        }
    });
</script>
</body>
</html>